package cn.iocoder.yudao.module.dating.controller.app.samllNote;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.annotations.PreAuthenticated;
import cn.iocoder.yudao.module.dating.controller.app.samllNote.vo.*;
import cn.iocoder.yudao.module.dating.enums.NotePayEnum;
import cn.iocoder.yudao.module.dating.service.smallNote.SmallNoteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

/**
 * <p>  </p>
 */
@Tag(name = "管理后台 - 小纸条")
@RestController
@RequestMapping("/dating/note")
@Validated
public class AppNoteController {
    @Resource
    private SmallNoteService smallNoteService;
    @PostMapping("/create")
    @Operation(summary = "创建小纸条")
    @PreAuthenticated
    public CommonResult<Long> createSmallNote(@Valid @RequestBody AppSmallNoteReqVO createReqVO) {
        return success(smallNoteService.createAppSmallNote(createReqVO));
    }
    @PostMapping("/take")
    @Operation(summary = "抽取小纸条")
    @PreAuthenticated
    public CommonResult<AppSmallNoteTakeResVO> takeSmallNote(@Valid @RequestBody AppSmallNoteTakeReqVO createReqVO) {
        return success(smallNoteService.takeSmallNote(createReqVO));
    }
    @GetMapping("/take/{id}")
    @Operation(summary = "抽取小纸条")
    @PreAuthenticated
    public CommonResult<AppSmallNoteTakeResVO> takeSmallNoteById(@PathVariable Long id) {
        return success(smallNoteService.takeSmallNoteById(id));
    }
    @GetMapping("/info/{id}")
    @Operation(summary = "查看小纸条")
    @PreAuthenticated
    public CommonResult<AppSmallNoteTakeResVO> infoSmallNoteById(@PathVariable Long id) {
        return success(smallNoteService.infoSmallNoteById(id));
    }
    @GetMapping("/push-list")
    @Operation(summary = "我放入的小纸条")
    @PreAuthenticated
    public CommonResult<PageResult<AppSmallNoteTakeResVO>> pushList(@Valid AppSmallNotePageReqVO pageReqVO) {

        return success(smallNoteService.pushList(pageReqVO));
    }
    @GetMapping("/take-list")
    @Operation(summary = "我抽取的小纸条")
    @PreAuthenticated
    public CommonResult<PageResult<AppSmallNoteTakeResVO>> takeList(@Valid AppSmallNotePageReqVO pageReqVO) {

        return success(smallNoteService.takeList(pageReqVO));
    }
    @GetMapping("/top-list")
    @Operation(summary = "精选的小纸条")
    public CommonResult<PageResult<AppSmallNoteCardResVO>> topList(@Valid AppSmallNotePageReqVO pageReqVO) {

        return success(smallNoteService.topList(pageReqVO));
    }
    @GetMapping("/square-list")
    @Operation(summary = "广场的小纸条")
    public CommonResult<PageResult<AppSmallNoteCardResVO>> squareList(@Valid AppSmallNotePageReqVO pageReqVO) {

        return success(smallNoteService.squareList(pageReqVO));
    }
    // 获取套餐列表
    @GetMapping("/tariff-list")
    @Operation(summary = "获取套餐列表")
    @PreAuthenticated
    public CommonResult<List<AppNoteTariffVO>> tariffList() {
        List<AppNoteTariffVO> list = Arrays.stream(NotePayEnum.values()).map(notePayEnum ->
                new AppNoteTariffVO(notePayEnum.getId(), notePayEnum.getMoney(), notePayEnum.getCurrency(), notePayEnum.getDes())
        ).collect(Collectors.toList());
        return success(list);
    }

}
